package com.mall.xiaomi.exception;

import com.mall.xiaomi.util.ResultMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @ClassName XmExceptionHandler
 * @Description TODO
 * @action luoliang
 * @Data 2021/2/25 19:18
 * @Version 1.0
 */
@ControllerAdvice
@ResponseBody
public class XmExceptionHandler {

    @Autowired
    private ResultMessage resultMessage;
    @ExceptionHandler(XmException.class)
    public ResultMessage handleException(XmException e){
        ExceptionEnum em = e.getExceptionEnum();
        resultMessage.fail(em.getCode() + "",em.getMsg());
        return resultMessage;
    }
}
